package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.User;

/**
 * Created by florian on 5/01/14.
 */
public class LoginPasswordController implements ScreenController {

    private final User user;
    private final ScreenControllerFactory screenControllerFactory;
    private final BibliotecaUI ui;

    public LoginPasswordController(User user, ScreenControllerFactory screenControllerFactory, BibliotecaUI ui) {
        this.user = user;
        this.screenControllerFactory = screenControllerFactory;
        this.ui = ui;
        ui.showPasswordMessage();
    }

    @Override
    public ScreenController processCommand(String line) {
        if (user==null || !user.isCorrectPassword(line)) {
            ui.showLoginUnsuccessful();
            return screenControllerFactory.createLoginController();
        }else {
            ui.showLoginSuccessful();
            return screenControllerFactory.createMainScreenControllerLoggedIn(user);

        }
    }
}

